package com.dao.impl;

import java.util.List;

import javax.annotation.Resource;

import org.hibernate.SessionFactory;
import org.hibernate.query.Query;
import org.springframework.stereotype.Repository;

import com.dao.ProductDao;
import com.entity.Product;

@Repository
public class ProductImpl implements ProductDao{
	@Resource
	private SessionFactory sessionFactory;
	@Override
	public List<Product> allProduct() {
		String hql="from Product";
		Query query = this.sessionFactory.getCurrentSession().createQuery(hql);
		List<Product> list=query.list();
		return list;
	}
	@Override
	public Product finProduct(int id) {
		
		Product product=this.sessionFactory.getCurrentSession().get(Product.class, id);
		return product;
	}
	@Override
	public List<Product> getPage(int page) {
		String hql="from Product";
		Query query = this.sessionFactory.getCurrentSession().createQuery(hql);
		query.setFirstResult((page-1)*4);
		query.setMaxResults(4);
		List<Product> list=query.list();
		return list;
	}
	@Override
	public int getCount() {
		return this.allProduct().size();
	}

}
